package com.ykl.demo.comp.conv;

import com.ykl.demo.comp.SpcRoomComp;
import com.ykl.demo.entity.SpcRoom;
import com.ykl.demo.model.RoomImportResModel;
import com.ykl.utils.Holder;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * .
 * <p></p>
 *
 * @author 王东石 2021/11/28 9:37.
 */
@Slf4j
@Component
public class RoomImportResModel2SpcRoomConv  extends AbstractConverter<RoomImportResModel, SpcRoom>{

    @Autowired
    private SpcRoomComp mmCmpRoom;

    @Override
    public SpcRoom conv(RoomImportResModel s) {

        Holder<Boolean> flgCreate = Holder.of(false);
        SpcRoom room = mmCmpRoom.findById(s.getRoomId()).orElseGet(
                ()->{
                    flgCreate.target=true;
                    return new SpcRoom();
                }
        );
        room.setChinaName(s.getChinaName());
        room.setAddress(s.getAddress());
        room.setClassId(Integer.parseInt(s.getClassId()));
        room.setTypeId(Integer.parseInt(s.getTypeId()));
        room.setStartUseDate(s.getStartUseDate());
        room.setStationId(s.getStationId());
        room.setX(s.getX());
        room.setY(s.getY());
        s.setReason(flgCreate.target?"新建":"更新");
        return room;
    }

}
